package com.rain.shoppingscienceproj.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.rain.shoppingscienceproj.R;
import com.rain.shoppingscienceproj.utils.ImageUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Rain
 * Create: 2017/12/13 14:00
 */

public class DetaileImageAdapter extends RecyclerView.Adapter<DetaileImageAdapter.MyViewHolder> {

    private Context mContext;
    String[] particulars;

    public DetaileImageAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public String[] getParticulars() {
        return particulars;
    }

    public void setParticulars(String[] particulars) {
        this.particulars = particulars;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout_detaile, parent, false);//解决宽度不能铺满
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String pic = particulars[position];
        ImageUtils.images(mContext, pic, holder.imageView);
    }

    @Override
    public int getItemCount() {
        if (particulars == null)
            return 0;
        else
            return particulars.length;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_detaile_image)
        ImageView imageView;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
